//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "SHDocVw_OCX"
#pragma resource "*.dfm"
Tfrmweb *frmweb;
MyDocHandler* dochandler;
//---------------------------------------------------------------------------
__fastcall Tfrmweb::Tfrmweb(TComponent* Owner)
  : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall Tfrmweb::FormCreate(TObject *Sender)
{
  dochandler = new MyDocHandler;
  webBrowser->Navigate(WideString(ExtractFilePath(Application->ExeName)+"\extweb.htm"));
//  webBrowser->Navigate(WideString("about:blank"));
  while(webBrowser->Busy)
      Application->ProcessMessages();

  ICustomDoc *custdoc;
  webBrowser->Document->QueryInterface(&custdoc);
  if (custdoc)
  {
    custdoc->SetUIHandler(dochandler);
    custdoc->Release();
  }
}
//---------------------------------------------------------------------------

void __fastcall Tfrmweb::FormClose(TObject *Sender, TCloseAction &Action)
{
  dochandler->Release();
}
//---------------------------------------------------------------------------
void __fastcall Tfrmweb::Button1Click(TObject *Sender)
{
  webBrowser->GoBack();
}
//---------------------------------------------------------------------------

void __fastcall Tfrmweb::Button2Click(TObject *Sender)
{
  CComPtr<IHTMLDocument3> doc;
  frmweb->webBrowser->Document->QueryInterface(IID_IHTMLDocument3,(void**)&doc);
  CComPtr<IHTMLElement> ele;
  HRESULT ret=doc->getElementById(L"posList",&ele);
  CComPtr<IHTMLTable> table;
  ele->QueryInterface(IID_IHTMLTable,(void**)&table);
  CComPtr<IHTMLTableRow> row;
  table->insertRow(-1,(IDispatch**)&row);
  IHTMLTableCell* cell;
  row->insertCell(-1,(IDispatch**)&cell);
  IHTMLElement* tdele;
  cell->QueryInterface(IID_IHTMLElement,(void**)&tdele);
  tdele->put_innerText(L"Unkown");
  tdele->Release();
  cell->Release();
  row->insertCell(-1,(IDispatch**)&cell);
  cell->QueryInterface(IID_IHTMLElement,(void**)&tdele);
  tdele->put_innerText(L"Good Postion");
  tdele->Release();
  cell->Release();
}
//---------------------------------------------------------------------------

